package com.aimi.service.impl;

import com.aimi.dao.UserDao;
import com.aimi.entity.User;
import com.aimi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service        //声明本类是一个业务层bean
public class UserServiceImpl implements UserService {
    @Autowired      //注入注解（按照类型注入）
    @Qualifier("userDao")       //指定注入对象名称,通常和@Autowired搭配使用
    private UserDao userDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)      //事务注解
    public List<User> queryUsers() {
        return userDao.selectAllUser();
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public User queryUser(Integer id) {
        return userDao.selectUserById(id);
    }

    @Override
    public void updateUser(User user) {
        System.out.println("已更改");

        userDao.updateUser(user);
    }

    @Override
    public void deleteUser(Integer id) {
        System.out.println("已删除");

        userDao.deleteUser(id);
    }
}
